{% extends 'users/usercenter-base.html' %}
{% load staticfiles %}

{% block title %}我的收藏- 谷粒教育网{% endblock %}

{% block breach %}我的收藏{% endblock %}

{% block reght %}
    <div class="right" >
        <div class="personal_des Releasecont">
            <div class="head">
                <h1>我的收藏</h1>
            </div>
        </div>

        <div class="personal_des permessage">
            <div class="head">
                <ul class="tab_header messagehead">
                    <li><a href="{% url 'users:user_loveorg' %}">课程机构</a> </li>
                    <li class="active"><a href="{% url 'users:user_loveteacher' %}">授课教师 </a></li>
                    <li><a href="{% url 'users:user_lovecourse' %}">公开课程</a></li>
                </ul>
            </div>

            <div class="messagelist">
            {% for teacher in teacher_list %}
                <div class=" butler_list butler-fav-box">
                    <dl class="des users">
                        <dt>
                            <a href="{% url 'orgs:teacher_detail' teacher.id %}">
                                <img width="100" height="100" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
                            </a>
                        </dt>
                        <dd>
                            <h1>
                                <a href="{% url 'orgs:teacher_detail' teacher.id %}">
                                    {{ teacher.name }}<span class="key">认证教师</span>
                                </a>
                            </h1>
                            <ul class="cont clearfix">
                                <li class="time">工作年限：<span>{{ teacher.work_year }}年</span></li>
                                <li class="c7">课程数：<span>{{ teacher.courseinfo_set.count }}</span></li>
                            </ul>
                            <ul class="cont clearfix">
                                <li class="time">工作公司：<span>{{ teacher.work_company.name }}</span></li>
                                <li class="c7">公司职位：<span>{{ teacher.work_position }}</span></li>
                            </ul>
                        </dd>
                        <div class="delete jsDeleteFav_teacher" data-favid="{{ teacher.id }}"></div>
                    </dl>
                </div>
            {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}

{% block user %}{% endblock %}

{% block myjs1 %}
    <script>
        // 页面加载完成
        $(function () {
            $('.delete').click(function () {
                {# prop()用来取元素自带属性的值或者设置值,attr()用来取元素自定义的属性的值或者设置值 #}
                var loveid = $(this).attr('data-favid');
                var lovetype = 3;  // 3表示讲师类型
                var obj = $(this);
                $.ajax({
                    type:'GET',
                    url:'{% url 'operations:user_deletelove' %}',
                    data:{
                        loveid:loveid,
                        lovetype:lovetype,
                    },
                    success:function (callback) {
                        if (callback.status == 'ok'){
                            alert(callback.msg);
                            {# window.location.reload();  // 取消收藏后页面刷新 #}
                            {# 拿到点击对象的祖先节点 当中有类名是des的祖先节点 然后在删除div 页面不刷新#}
                            obj.parents('.butler_list').remove();
                        } else{
                            alert(callback.msg);
                        }
                    }
                })
            });
        })

    </script>
{% endblock %}


